import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
* Created with IntelliJ IDEA.
* Description:
* User: 周斌
* Date: 2024-06-27
* Time: 17:13
*/
public class Deom29 {
        public static void main(String[] args) throws InterruptedException, ExecutionException {
            Callable<Integer> callable = new Callable<Integer>() {
                int sum = 0;
                @Override
                public Integer call() throws Exception {
                    for (int i = 1; i < 1000; i++) {
                        sum += i;
                    }
                    return sum;
                }
            };
            FutureTask<Integer> futureTask = new FutureTask<>(callable);
            Thread thread = new Thread(futureTask);
            thread.start();
            thread.join();
            System.out.println("sum = " + futureTask.get());
        }

}


